package com.huawei.hwid.e;

import android.content.Context;
import com.huawei.hms.framework.network.restclient.RestClient;
import com.huawei.hms.framework.network.restclient.RestClient.Builder;
import com.huawei.hms.framework.network.restclient.hwhttp.HttpClient;
import com.huawei.hwid.core.d.b.e;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import o.fuf;
import o.fut;
import o.fuv;
import o.fuv.b;

public class a {
    private static Map<String, RestClient> a = new HashMap();
    private static int b = 5;

    public static synchronized RestClient a(Context context, String str, int i) throws IOException {
        RestClient restClient;
        int i2 = 5;
        synchronized (a.class) {
            if (i >= 5) {
                i2 = i;
            }
            if (a.get(str) == null) {
                e.b("HwIdRestHttpClient", "getOkHttpClient == null  buildOkHttpClient", true);
                a.put(str, c(context, str, i2));
            } else if (b != i2) {
                a.remove(str);
                a.put(str, c(context, str, i2));
                e.b("HwIdRestHttpClient", "remove add", true);
            }
            b = i2;
            e.b("HwIdRestHttpClient", "getOkHttpClient host:" + str + "-connectionTime=" + i + "--size = " + a.size(), true);
            restClient = (RestClient) a.get(str);
        }
        return restClient;
    }

    private static RestClient c(Context context, String str, int i) throws IOException {
        return new Builder(context).baseUrl(str).validateEagerly(true).httpClient(new HttpClient.Builder().hostnameVerifier(com.huawei.hwid.vermanager.e.a().a(str)).sslSocketFactory(com.huawei.hwid.vermanager.e.a().a(context), com.huawei.hwid.vermanager.e.a().b(context)).connectTimeout(i).readTimeout(i).retryTimeOnConnectionFailure(1).build()).build();
    }

    public static fuv b(Context context, String str, int i) throws IOException {
        b bVar = new b();
        bVar.ˊ(new fuf(8, 10, TimeUnit.MINUTES));
        bVar.ˊ((long) i, TimeUnit.SECONDS);
        bVar.ॱ(true);
        bVar.ˎ(true);
        bVar.ˎ((long) i, TimeUnit.SECONDS);
        bVar.ˋ((long) i, TimeUnit.SECONDS);
        bVar.ˊ(com.huawei.hwid.vermanager.e.a().a(str)).ˋ();
        bVar.ॱ(Collections.unmodifiableList(Arrays.asList(new fut[]{fut.ˊ, fut.ˋ})));
        bVar.ॱ(com.huawei.hwid.vermanager.e.a().a(context), com.huawei.hwid.vermanager.e.a().b(context));
        bVar.ˎ(bVar.ˋ(fut.ˊ));
        return bVar.ˋ();
    }
}
